/**
 * 
 */
package com.gr.staffpm.datatypes;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Proxy;

/**
 * @author Graham Rhodes 3 Mar 2011 12:27:41
 */
@Entity
@Proxy(lazy = false)
@Table(name = "feedback")
public class Feedback implements Serializable, Comparable<Feedback> {

    private static final long serialVersionUID = 1L;
    public static final String RECEIVER = "receiver";
    public static final String CREATED = "created";
    public static final String RATING = "rating";
    private int feedId = 0;
    private Task task = null;
    private User receiver = null;
    private int rating = 0;
    private String comment = "";
    private User createdBy = null;
    private Date created = new Date();
    private User updatedBy = null;
    private Date lastUpdated = new Date();

    public Feedback() {

    }

    public Feedback(int rating, String comment, User creator, User receiver) {
        this(rating, comment, null, creator, receiver);
    }

    public Feedback(int rating, String comment, Task task, User creator, User receiver) {
        this.task = task;
        this.rating = rating;
        this.comment = comment;
        this.receiver = receiver;
        this.createdBy = creator;
        this.updatedBy = creator;
    }

    @Id
    @GeneratedValue
    @Column(name = "feed_id")
    public int getFeedId() {
        return feedId;
    }

    @ManyToOne
    @JoinTable(name = "feedback_tasks", joinColumns = @JoinColumn(name = "feed_id"), inverseJoinColumns = @JoinColumn(name = "task_id"))
    public Task getTask() {
        return task;
    }

    @ManyToOne
    @JoinColumn(name = "receiver")
    public User getReceiver() {
        return receiver;
    }

    @Basic
    @Column(name = "rating")
    public int getRating() {
        return rating;
    }

    @Lob
    @Column(name = "comment")
    public String getComment() {
        return comment;
    }

    @ManyToOne
    @JoinColumn(name = "createdBy")
    public User getCreatedBy() {
        return createdBy;
    }

    @Column(name = "created")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getCreated() {
        return created;
    }

    @ManyToOne
    @JoinColumn(name = "updatedBy")
    public User getUpdatedBy() {
        return updatedBy;
    }

    @Column(name = "lastUpdated")
    @Temporal(TemporalType.TIMESTAMP)
    public Date getLastUpdated() {
        return lastUpdated;
    }

    public void setFeedId(int feedId) {
        this.feedId = feedId;
    }

    public void setTask(Task task) {
        this.task = task;
    }

    public void setReceiver(User receiver) {
        this.receiver = receiver;
    }

    public void setRating(int rating) {
        this.rating = rating;
    }

    public void setComment(String comment) {
        this.comment = comment;
    }

    public void setCreatedBy(User createdBy) {
        this.createdBy = createdBy;
    }

    public void setCreated(Date created) {
        this.created = created;
    }

    public void setUpdatedBy(User updatedBy) {
        this.updatedBy = updatedBy;
    }

    public void setLastUpdated(Date lastUpdated) {
        this.lastUpdated = lastUpdated;
    }

    @Override
    public int compareTo(Feedback other) {
        return created.compareTo(other.getCreated());
    }

}
